import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int angle = scanner.nextInt();

        int[][] array = new int [n][n];
        for (int i = 0;i < n; i++){
            for (int j = 0; j < n; j++){
                array[i][j] = scanner.nextInt();
            }
        }
        if (angle == 90){
            for(int j = 0; j < n; j++)
            {
                for(int i = n - 1; i > 0; i--) {
                    System.out.print(array[i][j] + " ");
                }
               System.out.println(array[0][j]);
            }


        }
        if (angle == 180){
            for(int i = n - 1;i >= 0; i--){
                for(int j = n - 1; j > 0; j--) {
                    System.out.print(array[i][j] + " ");
                }
                System.out.println(array[i][0]);
            }
        }
        if (angle == -90){
            for(int j = n - 1; j >= 0; j--)
            {
                for(int i = 0; i < n - 1; i++)
                    System.out.print(array[i][j]+" ");
                System.out.println(array[n-1][j]);
            }
        }
    }
}
